#include "announcement.h"
#include "ui_announcement.h"
#include "reservehome.h"
#include "reserveannouncement.h"
#include "QMouseEvent"

announcement::announcement(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::announcement)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗口无边框
}

announcement::~announcement()
{
    delete ui;
}

void announcement::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
                initialMousePosition = event->globalPos(); // 记录鼠标按下时的全局位置
                isDragging = true; // 开始拖动
            }
    }

void announcement::mouseMoveEvent(QMouseEvent *event){
    if (isDragging && event->buttons() & Qt::LeftButton) {
                QPoint delta = event->globalPos() - initialMousePosition; // 计算鼠标移动的距离
                move(x() + delta.x(), y() + delta.y()); // 根据鼠标移动的距离来移动窗口
                initialMousePosition = event->globalPos(); // 更新鼠标位置
            }
    }
void announcement::mouseReleaseEvent(QMouseEvent *event) {
        if (event->button() == Qt::LeftButton) {
            isDragging = false; // 结束拖动
        }
    }

void announcement::on_pushButton_clicked()
{
    this->hide();
    reserveHome*r=new reserveHome;
    r->show();
}
//温馨提示
void announcement::on_pushButton_9_clicked()
{
    this->close();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "温馨提示："
                      "<ol style='margin-left: 20px;'>"
                      "<li>请勿携带电动车电池、易燃易爆危险物品入馆！</li>"
                      "<li>请勿在馆内使用大功率电器设备！</li>"
                      "</ol>";
    announcement->setContent(content);
    announcement->show();
}
//闭馆公告
void announcement::on_pushButton_8_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "温馨提示："
                      "<ol style='margin-left: 20px;'>"
                      "<li>新校区图书馆将于2024年11月16日闭关修缮，预计11月20日开放。</li>"
                      "</ol>";
    announcement->setContent(content);
    announcement->show();
}
//降温提示
void announcement::on_pushButton_7_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "温馨提示："
                      "<ol style='margin-left: 20px;'>"
                      "<li>近期天气变冷，图书馆将开发热空调使用。</li>"
                      "<li>请各位同学注意保暖。</li>"
                      "</ol>";
    announcement->setContent(content);
    announcement->show();
}
//展览更新
void announcement::on_pushButton_11_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "展览更新："
    "<ol style='margin-left: 20px;'>"
    "<li>新展览《历史长河》将于2024年12月26日开幕。</li>"
    "<li>展览将展示从古代至现代的珍贵文物，敬请期待。</li>"
    "</ol>";
    announcement->setContent(content);
    announcement->show();
}

//服务变更
void announcement::on_pushButton_14_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "服务变更："
    "<ol style='margin-left: 20px;'>"
    "<li>自2024年12月28日起，图书馆开放时间调整为09:00-17:00。</li>"
    "<li>请读者合理安排借阅时间，感谢您的理解与支持。</li>"
    "</ol>";
    announcement->setContent(content);
    announcement->show();
}

//开发通知
void announcement::on_pushButton_12_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "开发通知："
    "<ol style='margin-left: 20px;'>"
    "<li>本馆将于2024年12月27日进行系统升级，部分服务将暂停。</li>"
    "<li>预计升级时间为8小时，具体恢复时间另行通知。</li>"
    "</ol>";
    announcement->setContent(content);
    announcement->show();
}

//放假通知
void announcement::on_pushButton_13_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "放假通知："
    "<ol style='margin-left: 20px;'>"
    "<li>根据国家法定节假日安排，本馆将于2025年1月1日放假一天。</li>"
    "<li>1月2日恢复正常开放，祝大家节日快乐。</li>"
    "</ol>";
    announcement->setContent(content);
    announcement->show();
}

//紧急通知
void announcement::on_pushButton_15_clicked()
{
    this->hide();
    reserveHome::announcementIsHome = false;
    reserveAnnouncement *announcement = new reserveAnnouncement;
    QString content = "紧急通知："
    "<ol style='margin-left: 20px;'>"
    "<li>由于突发情况，本馆需立即疏散，请所有人员迅速有序离开。</li>"
    "<li>紧急疏散路线已在馆内各处标示，请遵循工作人员指引。</li>"
    "</ol>";
    announcement->setContent(content);
    announcement->show();
}
